import redis
import pymysql


class MyQueue:

    def __init__(self, keyname:str, **redis_kwargs):
        self.key = keyname
        self.__db = redis.Redis(**redis_kwargs)

    # 添加数据
    def push(self, x:str) -> None:
        # self.s.append(x)
        # 往数据库添加队列数据
        self.__db.rpush(self.key, x)

    # 获取数据
    def peek(self) -> str:
        return self.__db.lpop(self.key)

    # 判断是否执行完毕
    def empty(self) -> bool:
        return self.__db.llen(self.key)




# 数据库查询
class MysqlFind:

    def __init__(self, sql):
        self.db = pymysql.connect(host='127.0.0.1', port=3306, database='workflow', user='root', password="mysql", charset="utf8")
        self.cursor = self.db.cursor()
        self.sql = sql

    def sql_select(self):

        self.cursor.execute(self.sql)
        desc = self.cursor.description
        result = [dict(zip([col[0] for col in desc], row)) for row in self.cursor.fetchall()]
        return result

